package org.bai.meetingfilm.backend.film.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.bai.meetingfilm.backend.common.utils.PageUtil;
import org.bai.meetingfilm.backend.film.controller.vo.DescribeActorsRespVO;
import org.bai.meetingfilm.backend.film.controller.vo.DescribeFilmRespVO;
import org.bai.meetingfilm.backend.film.controller.vo.DescribeFilmsRespVO;
import org.bai.meetingfilm.backend.film.service.FilmService;
import org.bai.meetingfilm.common.vo.BasePageRepVO;
import org.bai.meetingfilm.common.vo.BasePageReqVO;
import org.bai.meetingfilm.common.vo.BaseResponseVO;
import org.bai.meetingfilm.exception.CommonServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName FilmController
 * @Description 影片模块Controller
 * @Author bai
 * @Date 2021/7/18 17:54
 * @Version 1.0
 **/
@RestController
@RequestMapping("/films")
public class FilmController {

    private static final Logger LOGGER = LoggerFactory.getLogger(FilmController.class);

    private final FilmService filmService;

    @Autowired
    public FilmController(FilmService filmService) {
        this.filmService = filmService;
    }

    @GetMapping(value = "/actors")
    public BaseResponseVO<BasePageRepVO<DescribeActorsRespVO>> describeActors(BasePageReqVO pagesVO) throws CommonServiceException {
        pagesVO.checkParam();

        IPage<DescribeActorsRespVO> result = filmService.describeActors(pagesVO.getNowPage(), pagesVO.getPageSize());
        BasePageRepVO<DescribeActorsRespVO> pageRepVO = PageUtil.buildBasePageRepVO(result);
        return BaseResponseVO.success(pageRepVO);
    }

    @GetMapping(value = "/")
    public BaseResponseVO<BasePageRepVO<DescribeFilmsRespVO>> describeFilms(BasePageReqVO pagesVO) throws CommonServiceException {
        pagesVO.checkParam();

        IPage<DescribeFilmsRespVO> result = filmService.describeFilms(pagesVO.getNowPage(), pagesVO.getPageSize());
        BasePageRepVO<DescribeFilmsRespVO> pageRepVO = PageUtil.buildBasePageRepVO(result);
        return BaseResponseVO.success(pageRepVO);
    }

    @GetMapping(value = "/{filmId}")
    public BaseResponseVO<DescribeFilmRespVO> describeFilmsById(@PathVariable(value = "filmId") String FilmId) throws CommonServiceException {
        DescribeFilmRespVO result = filmService.describeFilmsById(FilmId);
        return BaseResponseVO.success(result);
    }
}
